package com.inhgroup.flashcards.data;

/**
 * An individual flash card with contents on front and back.
 * 
 * This will actually be displayed on the left and right of the window.
 * 
 * As of this writing, Card instances should be immutable.
 * 
 * @author Branden Ogata
 *
 */

public class Card
{
  /**
   * The contents of the front/left side of this Card.
   * 
   */
  private String front;
  
  /**
   * The contents of the back/right side of this Card.
   * 
   */
  private String back;
  
  /**
   * Creates a new Card.
   * 
   * @param front The String containing the value on the front side of this Card.
   * @param back The String containing the value on the back side of this Card.
   * 
   */
  
  public Card(String front, String back)
  {
    this.front = front;
    this.back = back;
  }

  /**
   * Returns the contents on the front of this Card.
   * 
   * @return A String containing the value on the front side of this Card.
   * 
   */
  
  public String getFront()
  {
    return this.front;
  }

  /**
   * Returns the contents to display on the left side of the window.
   * 
   * @return A String containing the value of the Card to display on the left side of the window.
   * 
   */
  
  public String getLeft()
  {
    return this.getFront();
  }

  /**
   * Returns the contents on the back of this Card.
   * 
   * @return A String containing the value on the back side of this Card.
   * 
   */

  public String getBack()
  {
    return this.back;
  }
  
  /**
   * Returns the contents to display on the right side of the window.
   * 
   * @return A String containing the value of the Card to display on the right side of the window.
   * 
   */

  public String getRight()
  {
    return this.getBack();
  }
  
  /**
   * Indicates whether the parameter is equal to this Card.
   * 
   * Used primarily in testing.
   * 
   * @param obj The Object to compare to this Card.
   * 
   * @return A boolean that is true if the parameter is equal to this card, 
   *                           false otherwise.
   *                           
   */
  
  @Override
  public boolean equals(Object obj)
  {
    boolean equality = false;
    
    if (this == obj)
    {
      equality = true;
    }
    else if (obj instanceof Card)
    {
      Card temp = (Card) obj;
      equality = (this.getFront().equals(temp.getFront())) && 
                 (this.getBack().equals(temp.getBack()));
    }
    
    return equality;
  }
  
  /**
   * Returns a hash code for this Card.
   * 
   * @return An int equal to the hash code for this Card.
   * 
   */
  
  @Override
  public int hashCode()
  {
    int result = 7;
    int combination = this.front.hashCode() + this.back.hashCode();
    result = combination * 23;
    return result;
  }
}